﻿//Copyright (C) <2013>  <jonathan cleeve norton> All Rights Reserved 
//Contact jon.norton@fin-plus.co.uk website <http://www.fin-plus.co.uk/>
using System;
using System.Windows;
using FinPlusCommon;
using log = Logger.Logger;

namespace FinPlusWPFControls
{
    public partial class FinPlusColValueShiftButton : FinPlusControl
    {
        public event EventHandler<IFunction> ColShift;
        
        //construct
        public FinPlusColValueShiftButton(string shift)
        {
            InitializeComponent();
            colShift.Content = Id = shift.Split(',')[0];
            Tag = shift;
            IsValid = true;
        }

        //common control interface
        public override void CmdExecute(IFunction command)
        {
            try
            {
                CmdCapture(command);

                switch ((Cmds)Enum.Parse(typeof(Cmds), command.Name, true))
                {
                    case Cmds.ColValueShiftUp: 
                    case Cmds.ColValueShiftDown:
                    case Cmds.ColValShiftLevel: ColValueShift(command); break;
                    default: throw new Exception(string.Format("event not recognised {0}", command.Name));
                }
            }
            catch (CmdExecuteException e)
            {
                IsValid = log.Log(Logger.Level.Warning, Id, Config, e.Message, e);
            }
        }

        //private
        private void ColValueShift(IFunction func)
        {
            ColShift.Invoke(this, (Function)func);
        }

        //cmds
        private enum Cmds { ColValueShiftUp, ColValueShiftDown, ColValShiftLevel }
   }
}
